// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

#include "stdafx.h"


BOOL APIENTRY DllMain(
    HMODULE module,
    DWORD reason,
    LPVOID reserved)
{
    UNREFERENCED_PARAMETER(module);
    UNREFERENCED_PARAMETER(reserved);

    switch (reason)
    {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
    }
    return TRUE;
}


//
// WARNING: 
//
// The signature below MUST exactly match (including the parameter names)
// with the signature generated by MIDL in the FabricServiceCommunication.h file. 
// Otherwise the linker does not apply the extern "C" specifier and exports 
// this function as C++ name mangled function instead of C style function.
// 
/* [entry] */ HRESULT CreateFabricTransportListener(
    /* [in] */ __RPC__in REFIID interfaceId,
    /* [in] */ __RPC__in  FABRIC_TRANSPORT_SETTINGS *settings,
    /* [in] */ __RPC__in FABRIC_TRANSPORT_LISTEN_ADDRESS *address,
    /* [in] */ __RPC__in  IFabricTransportMessageHandler *clientRequestHandler,
    /* [in] */ __RPC__in IFabricTransportConnectionHandler *clientConnectionHandler,
    /* [in] */ __RPC__in  IFabricTransportMessageDisposer *diposeProcessor,
    /* [out, retval] */ __RPC__deref_out_opt IFabricTransportListener ** listener)
{
    auto &providerFactory = Communication::TcpServiceCommunication::ServiceCommunicationListenerFactory::GetServiceCommunicationListenerFactory();

    Api::ComFabricTransportListenerFactory comFactory(providerFactory);

    return comFactory.CreateFabricTransportListener(interfaceId, settings, address,clientRequestHandler, clientConnectionHandler, diposeProcessor, listener);
}


HRESULT CreateFabricTransportClient(
    /* [in] */ __RPC__in REFIID interfaceId,
    /* [in] */ __RPC__in FABRIC_TRANSPORT_SETTINGS *settings,
    /* [in] */ __RPC__in LPCWSTR connectionAddress,
    /* [in] */ __RPC__in IFabricTransportCallbackMessageHandler *notificationHandler,
    /* [in] */ __RPC__in IFabricTransportClientEventHandler *connectionEventHandler,
    /* [in] */ __RPC__in  IFabricTransportMessageDisposer *messageDisposer,
    /* [out, retval] */ __RPC__deref_out_opt IFabricTransportClient **client)
{

    auto &comFactory = Api::ComFabricTransportClientFactory::GetComFabricTransportClientFactory(messageDisposer);

    return  comFactory.CreateFabricTransportClient(interfaceId, connectionAddress, settings, notificationHandler, connectionEventHandler,client);

}
